package com.comcontroller;

import com.mapper.User;
import com.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;

    @RequestMapping("/hello")
    @ResponseBody
    public String test(){
        return "hello ssm";
    }

    @RequestMapping("/{id}")
    @ResponseBody
    public User queryUserById(@PathVariable("id")int id){
        return this.userService.queryById(id);
    }
    @RequestMapping("/queryAll")
    public String queryAll(HttpServletRequest request){
        List<User> users = userService.queryAll();
        request.setAttribute("users",users);
        return "users";
    }

}